<?php
class Model extends RedBean_SimpleModel {

    private $errorCount = 0;
    private $errors = array();

    public function validate_empty($field, $message) {
        $value = $this->__get($field);
        $value = trim($value);

        if (empty($value)) {
            $this->addError($field,$message);
        }
    }

    public function hasErrors() {
        return ($this->errorCount > 0);
    }

    public function getErrors() {
        return $this->errors;
    }

    private function addError($field, $message) {
        $this->errors[$field][] = $message;
        $this->errorCount++;
    }
}

?>
